<g:if test="${!ajaxCall}">
  <html>
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
      <meta name="layout" content="save_undo" />
      <title>${Inter.printOut('Show Project',session.language)} ${fieldValue(bean:projectInstance, field:'name')}</title>
    </head>
    <body>

      <div class="undernav">
        <span class="menuButton"><g:link class="create" action="create">${Inter.printOut('New Project',session.language)}</g:link></span>
        <!-- This is the help button. -->
<%  def help = Help.findByNameAndLanguage("project_show", session.language)
def helplink = createLink(action:'show', controller:'help', id: help?.id )%>
        <a href="#" class="menulink" onClick="MyWindow=window.open('${helplink}','Help','width=350,height=450'); return false;">${Inter.printOut('Help',session.language)}</a>
        <!-- This is the end of the help button. -->
      </div>
      <!-- display only if the current mode allows it -->
      <!--   <div class="mode">
         <span style="font-weight:bold">
         <g:if test="${session.mode == null || session.mode.equalsIgnoreCase('sandbox')}">
${Inter.printOut('Sandbox mode',session.language)}
         <g:btnSaveUndo currentView="show" currentController="project" idProject="${projectInstance?.id}" />
         </g:if>
         <g:else>
${Inter.printOut('Budget mode',session.language)}
         </g:else>
           </span>
       </div> -->

      <div class="body" style="width:98%;">
</g:if>
<g:link class="hidden urlUpdateIncome" controller="project" action="updateIncome"></g:link>
<g:link class="hidden urlUpdateVariableCost" controller="project" action="updateVariableCost"></g:link>
<g:link class="hidden urlUpdate" controller="project" action="updateExpenditure"></g:link>
<g:link class="hidden urlUpdateHours" controller="project" action="updateHours"></g:link>

<input type="hidden" value="${fieldValue(bean:projectInstance, field:'id')}" id="projectId" />
 <!-- <h1>${Inter.printOut('Project',session.language)}: ${fieldValue(bean:projectInstance, field:'name')}</h1> -->
<g:if test="${flash.message}">
  <div class="message">${flash.message}</div>
</g:if>
<div class="showProject" style="margin-top:10px;">
  <div style="width:100%; border: 1px solid #ccc;">
    <div class="projectPic" style="float:left; margin:20px 0px 10px 20px; width:128px;">
              <img src="${resource(dir:'images/skin',file:'project.png')}" alt="Employee" style="margin-top:10px;" />
            </div>

<div class="projectInfo" style="float:left;margin:5px 0px 5px 20px; width:60%">
  <h2 style="margin-left:5px;">${fieldValue(bean:projectInstance, field:'name')}</h2>
     <table style="border:none;table-layout:fixed;">
        <tbody>
          <tr class="prop">
            <td valign="top" class="name" style="font-weight:bold">${Inter.printOut('Activity Id',session.language)}:</td>

            <td valign="top" class="value">${fieldValue(bean:projectInstance, field:'activityId')}</td>

          </tr>

          

          <tr class="prop">
            <td valign="top" class="name" style="font-weight:bold">${Inter.printOut('Description',session.language)}:</td>

            <td valign="top" class="value">${fieldValue(bean:projectInstance, field:'description')}</td>

          </tr>

          <tr class="prop">
            <td valign="top" class="name" style="font-weight:bold">${Inter.printOut('Area',session.language)}:</td>

            <td valign="top" class="value"><g:link controller="area" action="show" id="${projectInstance?.area?.id}">${projectInstance?.area?.encodeAsHTML()}</g:link></td>

        </tr>
        <tr class="prop">
          <td valign="top" class="name" style="font-weight:bold">${Inter.printOut('Start Date',session.language)}:</td>

          <td valign="top" class="value"><g:formatDate date="${projectInstance.startDate}" format="yyyy-MM-dd" /></td>

        </tr>
        <tr class="prop">
          <td valign="top" class="name" style="font-weight:bold">${Inter.printOut('End Date',session.language)}:</td>

          <td valign="top" class="value"><g:formatDate date="${projectInstance.endDate}" format="yyyy-MM-dd" /></td>

        </tr>
        <tr class="prop">
          <td valign="top" class="name" style="font-weight:bold">Status:</td>

          <td valign="top" class="value">${Inter.printOut(projectInstance.calcStatus(),session.language)}</td>

        </tr>
        </tbody>
      </table>
</div>
      
<%
def a = session.access
a.refresh()
%>
      <div class="buttons" style="clear:both">
        <g:if test="${(!session.mode.equalsIgnoreCase('budget')) || (session.mode.equalsIgnoreCase('budget') && !a.isBudgetLocked())}">
          <g:form>
            <input type="hidden" name="id" value="${projectInstance?.id}" />
            <span class="button"><g:actionSubmit class="edit" value="${Inter.printOut('Edit',session.language)}" action="Edit"/></span>
            <span class="button"><g:actionSubmit class="delete" onclick="return confirm('${Inter.printOut('Sure',session.language)}');" value="${Inter.printOut('Delete',session.language)}" action="Delete"/></span>
          </g:form>
        </g:if>
        <g:else>
          Budget locked, project not editable
        </g:else>
      </div>

    
    </div>


<%
Float fixedCost=0
// Float feeRentCost=0
//Float salaryCost=0
//Double sumDriftCost=0
Float travelCost=1
//Float oHCost=0
//Float sumOfCost=0


%>

      <div class="projectMembers" style="float:left; width:100%; margin-top:10px;">
      <h2>${Inter.printOut('Employees in project',session.language)}</h2>
      <g:if test="${projectInstance?.amountOfHour && (projectInstance?.amountOfHour?.size()>0)}">
        <table class="sortableTable {sortlist: [[0,0],[1,0]]}" style="table-layout:fixed">
      </g:if>
      <g:else>
        <table class="sortableTable" style="table-layout:fixed">
      </g:else>
      <thead>
        <tr>
          <th class="{sorter: 'link'}"><span class="a">${Inter.printOut('First Name',session.language)}</span></th>
          <th class="{sorter: 'link'}"><span class="a">${Inter.printOut('Last Name',session.language)}</span></th>
          <th class="{sorter: 'link'}"><span class="a">${Inter.printOut('salary',session.language)} (kr)</span></th>
          <th class="{sorter: 'numeric'}"><span class="a">${Inter.printOut('Hours',session.language)} (h)</span></th>
          <th class="{sorter: 'numeric'}"><span class="a">${Inter.printOut('percentage work',session.language)} (%)</span></th>
          <th class="{sorter: 'numeric'}" width="10%"><span class="a">${Inter.printOut('Cost',session.language)} (kr)</span></th>
        </tr>
      </thead>

      <tbody>
      <g:each var="m" in="${projectInstance.amountOfHour}">
        <tr>
          <td><g:link action="show" controller="employee" id="${m?.member?.id}">${m?.member?.firstName} </g:link></td>
        <td><g:link action="show" controller="employee" id="${m?.member?.id}">${m?.member?.lastName} </g:link></td>
        <td><g:link action="show" controller="employee" id="${m?.member?.id}"><g:formatNumber number="${m?.member?.yearlySalary()}" format="###"/> </g:link></td>
        <td><span class="hoursFigures" id="updateHours" title="${m?.id}"><g:formatNumber number="${m?.hours}" format="###"/><img alt="edit" style="vertical-align:text-bottom;" src="${resource(dir:'images/skin',file:'pencil.png')}"/></span></td>
        <td><span class="hoursFigures" id="updateProjectPercentage" title="${m?.id}"><g:formatNumber number="${(m?.hours/m.member.hoursForAge())*100}" format="###"/><img alt="edit" style="vertical-align:text-bottom;" src="${resource(dir:'images/skin',file:'pencil.png')}"/></span></td>
        <td><span class="hoursFigures" id="updateHours" title="${m?.id}"><g:formatNumber number="${m?.costOneEmployee()}" format="###"/></span></td>
        </tr>

<%
fixedCost += (m?.hours/m.member.hoursForAge()) * m?.member?.salary

//salaryCost += m?.costOneEmployee()
//sumDriftCost += m?.driftCost()

%>

      </g:each>
      </tbody>
      </table>
      <table width="99%">

      </table>

      <g:if test="${(!session.mode.equalsIgnoreCase('budget')) || (session.mode.equalsIgnoreCase('budget') && !a.isBudgetLocked())}">
        <div class="buttons">
          <g:form>
            <input type="hidden" name="id" value="${projectInstance?.id}" />
            <span class="button"><g:actionSubmit action ="add_employee" class="add_employee"  value="${Inter.printOut('Add Employee',session.language)}" /></span>
            <g:if test="${numberOfEmployees > 0}">
              <span class="button"><g:actionSubmit action ="delete_employee" class="delete_employee"  value="${Inter.printOut('Remove Employee',session.language)}" /></span>
            </g:if>
          </g:form>
              
        </div>
      </g:if>
   </div>
    
      <!-- NEW TABLE FOR PROJECT BUDGET -->

      
      <!-- <g:link class="hidden urlUpdate" controller="project" action="travelExpences"></g:link> -->
      <div class="projectCost" style="position:static;float:left; width:50%;margin-top:10px;">
        <h2>${Inter.printOut('Costs',session.language)} (kr)</h2>
        <table class="detailedCost">
          <tbody>
            <tr class="prop">
              <td valign="top" class="name" >${Inter.printOut('Total Salary Cost',session.language)}:
                <g:formatNumber number="${projectInstance?.currentBudget()?.sumSalaryCost()}" format="###" />
              </td>

              <td valign="top" class="name" >${Inter.printOut('Administrative overhead',session.language)}:
              <g:formatNumber number="${projectInstance?.currentBudget()?.oHCost()}" format="###" />
              </td>
          </tr>

          <tr class="prop">
            <td valign="top" class="name">
              ${Inter.printOut('Operation Cost',session.language)}:
              <g:formatNumber number="${projectInstance?.currentBudget()?.sumDriftCost()}" format="###" />
            </td>
            <td>
              <span class="itCostTitle">${Inter.printOut('IT-related Costs',session.language)}: </span>

              <g:if test="${(!session.mode.equalsIgnoreCase('budget')) || (session.mode.equalsIgnoreCase('budget') && !a.isBudgetLocked())}">
                <span id="itcost" class="incomeFigures itCost"> <g:formatNumber number="${projectInstance?.currentBudget()?.itCost}" format="###"/> <img alt="edit" class="pen" style="vertical-align:text-bottom;" src="${resource(dir:'images/skin',file:'pencil.png')}"/></span>
              </g:if>
              <g:else>
                <span id="itcost" class=" itCost"><g:formatNumber number="${projectInstance?.currentBudget()?.itCost}" format="###"/></span>

              </g:else>
            </td>                                                                                                                     
          </tr>
<%
def here = false
%>
          <g:each in="${projectInstance.currentBudget().variableCosts.sort {it.id}}" status="i" var="variableCost">
            <g:if test="${variableCost.category.name.equals('Travel') && !here}">
<%
here = true
%>
              <tr class="prop">

                <td valign="top" class="name">${Inter.printOut(variableCost.category.name,session.language)}:
                
                  <g:if test="${(!session.mode.equalsIgnoreCase('budget')) || (session.mode.equalsIgnoreCase('budget') && !a.isBudgetLocked())}">
                    <span id="variableCost_${variableCost.id}" class="variableCostFigures"><g:formatNumber number="${variableCost.amount}" format="###"/> <img alt="edit" style="vertical-align:text-bottom;" src="${resource(dir:'images/skin',file:'pencil.png')}"/></span>

                  </g:if>
                  <g:else>
                    <span id="variableCost_${variableCost.id}" class=""><g:formatNumber number="${variableCost.amount}" format="###"/></span>

                  </g:else>
<%

travelCost=variableCost.amount
%>
                </td>
                <td valign="top" class="name">
                  ${Inter.printOut('Fees and Rent',session.language)}:
                 <g:formatNumber number="${projectInstance?.currentBudget()?.feeRentCost()}" format="###" />
                 </td>
              </tr>
            </g:if>
          </g:each>
<%
//feeRentCost = (salaryCost+sumDriftCost+travelCost)*0.05
//oHCost = (salaryCost+sumDriftCost+travelCost)*0.4

//sumOfCost = iTCost+oHCost+feeRentCost+travelCost+sumDriftCost+salaryCost
%>
          
            
          
          <tr class="prop">
            <td valign="top" class="name" style="font-weight:bold;">${Inter.printOut('Total costs',session.language)}:
              <g:formatNumber number="${projectInstance?.currentBudget()?.sumOfCost()}" format="###" />
            </td>
          </tr>
          </tbody>
        </table>
      </div>
     
      <!--New table for incomes -->
      <div class="projectIncome" style="position:static;float:left; width:45%;margin-left:5%;margin-top:10px;">
        <h2>${Inter.printOut('Incomes',session.language)} (kr)</h2>
        <table>
          <tbody>
            <tr class="prop">
              <td valign="top" class="name">${Inter.printOut('Known Incomes',session.language)}:</td>

              <td valign="top" class="value">
          <g:if test="${(!session.mode.equalsIgnoreCase('budget')) || (session.mode.equalsIgnoreCase('budget') && !a.isBudgetLocked())}">
            <span id="knownIncome" class="incomeFigures"><g:formatNumber number="${projectInstance?.currentBudget()?.knownTotalIncome}" format="###"/> <img alt="edit" class="pen" style="vertical-align:text-bottom;" src="${resource(dir:'images/skin',file:'pencil.png')}"/></span>
          </g:if>
          <g:else>
            <span id="knownIncome" ><g:formatNumber number="${projectInstance?.currentBudget()?.knownTotalIncome}" format="###"/></span>
          </g:else>
          <span class="modifyInput"> </span>
          </td>

          </tr>

          <tr class="prop">
            <td valign="top" class="name">${Inter.printOut('Expected Incomes',session.language)}:</td>

            <td valign="top" class="value">
          <g:if test="${(!session.mode.equalsIgnoreCase('budget')) || (session.mode.equalsIgnoreCase('budget') && !a.isBudgetLocked())}">
            <span id="expectedIncome" class="incomeFigures"><g:formatNumber number="${projectInstance?.currentBudget()?.expectedTotalIncome}" format="###"/> <img alt="edit" class="pen" style="vertical-align:text-bottom;" src="${resource(dir:'images/skin',file:'pencil.png')}"/></span>
          </g:if>
          <g:else>
            <span id="expectedIncome"><g:formatNumber number="${projectInstance?.currentBudget()?.expectedTotalIncome}" format="###"/></span>

          </g:else>

          </td>

          </tr>

          <tr class="prop">
            <td valign="top" class="name" style="font-weight:bold;">${Inter.printOut('Total Incomes',session.language)}:</td>

            <td valign="top" class="value"><span id="totlalIncome" class=""><g:formatNumber number="${projectInstance?.currentBudget()?.calcTotalIncome()}" format="###"/></span></td>

          </tr>
          <tr class="prop" style="height:17px;"></tr>



          </tbody>
        </table>

        <!--End of new table for incomes -->

      </div>
        </div>
<%
//result = projectInstance?.currentBudget()?.calcTotalIncome() - sumOfCost
%>

  <div style="float:right; margin-right:10px;margin-top:5px;">
              <div style="float:left;margin:0; padding:0">
                 <p style="color:#006dba; font-weight:bold;">${Inter.printOut('Result',session.language)}:</p>
              </div>
   <div style="float:left;margin-left:5px; font-weight:bold; color:red;"><p><g:formatNumber number="${projectInstance?.currentBudget()?.calculationResult()}" format="###"/> kr</p></div>
        </div>




  </div>


</div>



<div class="dialog">









</div>
<g:if test="${!ajaxCall}">
</div>

</body>
</html>
</g:if>
